package com.duapk.search.util;


/**
 * 字符串工具类
 * 
 * @Package: com.duapk.search.util
 * @ClassName: StringTools
 * @author: jiangzheng
 * @date: Apr 4, 2011 7:50:10 PM
 * 
 */
public class StringTools {

	/**
	 * 将字符串转换为整数
	 * 
	 * @Title: parseInt
	 * @author: jiangzheng
	 * @date: Apr 4, 2011 7:50:33 PM
	 * @param str
	 * @param defaultNumber
	 * @return
	 */
	public static int parseInt(String str, int defaultNumber) {
		int number = defaultNumber;
		if (str != null) {
			try {
				number = Integer.parseInt(str);
			} catch (NumberFormatException e) {
				// 不处理
			}
		}
		return number;
	}

	/**
	 * 将指定的字符串转换为浮点数
	 * 
	 * @Title: parseFloat
	 * @author: jiangzheng
	 * @date: Jun 9, 2011 2:34:00 PM
	 * @param str
	 * @param defaultNumber
	 * @return
	 */
	public static float parseFloat(String str, float defaultNumber) {
		float number = defaultNumber;
		if (str != null && !str.isEmpty()) {
			try {
				number = Float.parseFloat(str);
			} catch (NumberFormatException e) {
				// 不处理
			}
		}
		return number;
	}

	/**
	 * 将指定的字符串转换为长整数
	 * 
	 * @Title: parseLong
	 * @author: jiangzheng
	 * @date: Jun 9, 2011 2:38:34 PM
	 * @param str
	 * @param defaultNumber
	 * @return
	 */
	public static long parseLong(String str, long defaultNumber) {
		long number = defaultNumber;
		if (str != null && !str.isEmpty()) {
			try {
				number = Long.parseLong(str);
			} catch (NumberFormatException e) {
				// 不处理
			}
		}
		return number;
	}
}
